//
//  WYWMainController.swift
//  WYWImitateMicroBlog
//
//  Created by 王永旺永旺 on 2016/10/22.
//  Copyright © 2016年 wangwang. All rights reserved.
//

import UIKit

class WYWMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = WYWTabBar()
        setValue(tabBar, forKey: "tabBar")
        
          //MARK: - 相应的WYWHomeController WYWMessageController WYWDiscoverController WYWComposeController 
//        let homeVc = WYWHomeController()
        
         //MARK: - 2种设置导航栏和底部的TabBar的标题的方式
//        homeVc.navigationItem.title = "首页"
//        homeVc.tabBarItem.title = "首页"
//        homeVc.title = "首页"
        
//        addChildViewController(homeVc)
        
        //依次添加这四个控制器
        addChildViewController(vc: WYWHomeController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(vc: WYWMessageController(), title: "信息", imgName: "tabbar_message_center")
        addChildViewController(vc: WYWDiscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(vc: WYWProfileController(), title: "我的", imgName: "tabbar_profile")
        
//=========================================================================
        

    }
    
    //====================================================================
     //MARK: - 进一步完善方法，可以把图标显示出来
    func addChildViewController(vc: UIViewController,title: String,imgName: String){
        //设置各个控制器的标题
        vc.title = title
        //设置文字的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: WYWCOLOR], for: UIControlState.selected)
        //设置每个控制器底部的相应的正常的状态的图标
        vc.tabBarItem.image = UIImage(named: imgName)
        //设置每个控制器底部的相应的高亮的状态的图标 这个高亮状态注意要用的是设置为原始的模式的那种
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected)")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //把底部的各个控制器当做导航控制器的根控制器
        let navVc = UINavigationController.init(rootViewController: vc)
        //把导航控制器设置为TabBarController的根控制器
        addChildViewController(navVc)
        
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
